// pages/production/production.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mycurrent: '待采购',
    user: wx.getStorageSync('user'),
    myList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      user: wx.getStorageSync('user')
    })
  },
  MyonChange(e) {
    console.log('onChange', e)
    this.setData({
      mycurrent: e.detail.key,
    })
    this.getlist()
  },
  getlist: function() {
    var that = this
    wx.request({
      url: app.globalData.api + 'productionOrderForm/myList',
      data: {
        "keyword": "",
        "orderBy": "",
        "status": this.data.mycurrent,
        "businessManagerId": "",
        "timeRange": "",
        "page": "",
        "rows": 99
      },
      header: {
        Authorization: wx.getStorageSync('token')
      },
      method: 'POST',
      success: function(res) {
        console.log(res)
        if (res.data.code == 200) {
          that.data.myList = res.data.data.productionOrderFormList
          for (var i in that.data.myList) {
            that.data.myList[i].needReissue = false
            for (var n in that.data.myList[i].productionItemList) {
              if (that.data.myList[i].productionItemList[n].remainderQuantity != 0) {
                that.data.myList[i].needReissue = true
              }
            }
          }


          that.setData({
            myList: that.data.myList
          })
        } else {
          that.setData({
            myList: []
          })
        }
      }
    })
  },
  edit: (e) => {
    wx.navigateTo({
      url: '/pages/signFabric/signFabric?id=' + e.currentTarget.dataset.id
    })
  },
  see: (e) => {
    wx.navigateTo({
      url: '/pages/production_order/production_order?id=' + e.currentTarget.dataset.id
    })
  },
  tailor: (e) => {
    wx.navigateTo({
      url: '/pages/tailorFabric/tailorFabric?id=' + e.currentTarget.dataset.id
    })
  },
  deliver: (e) => {
    wx.navigateTo({
      url: '/pages/deliver/deliver?id=' + e.currentTarget.dataset.id
    })
  },
  sjt(e){
    wx.navigateTo({
      url: '/pages/details/details?id=' + e.currentTarget.dataset.id+'&sc=true'
    })
  },
  goImg(e) {
    wx.request({
      url: app.globalData.api + 'designDiagram/findDesignDiagramStyleNumber/' + e.currentTarget.dataset.imgid,
      data: '',
      header: {
        Authorization: wx.getStorageSync('token')
      },
      success: function (res) {
        if (res.data.code == 200) {
          wx.navigateTo({
            url: '/pages/details/details?id=' + res.data.data.id,
          })
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.errorMsg,
          })
        }

      }
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getlist()
    this.setData({
      user: wx.getStorageSync('user')
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})